package za.ac.wits.elen7045.persistence.encryption;

import javax.crypto.Cipher;
import za.ac.wits.elen7045.persistence.exception.EncryptionException;

public class BasicSymmetricEncryptor extends TwoWayEncryptor {

	private final byte[] SALT = "some salt".getBytes(); 
    
	public BasicSymmetricEncryptor() {
		super("PBEWithMD5AndDES");
	}

	@Override
	protected String getPassword() {
		return "AzBy1029@)#(";
	}

	@Override
	public String encrypt(String plainText) throws EncryptionException {
		try {
		    Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
		    return base64Encode(cipher.doFinal(plainText.getBytes()));
		} catch (Exception e) {
			throw new EncryptionException(e);
		}
	}

	@Override
	public String decrypt(String encryptedText) throws EncryptionException {
		try {
		    Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
		    return new String(cipher.doFinal(base64Decode(encryptedText)));
		} catch (Exception e) {
			throw new EncryptionException(e);
		}
	}
	
}
